<template>
   <div>
    <span id="userName" >{{loginName}}</span>
    <el-button type="danger" @click="logout">{{logoutLetter}}</el-button>
   </div>
</template>

<script>
import axios from "axios";
export default {
    data() {
        return {
            loginName:'',
            logoutLetter:'注销'
        }
    },
    mounted() {
            axios.get('/admins/islogin').then(res => {
                if(res.data.isLogin) {
                    this.loginName = res.data.admin
                } else {
                    this.$router.push("/");
                }
            })
    },
    methods: {
        logout() {
             axios.get('/admins/logout').then(res => {
                if(res.data) {
                     this.loginName = ''
                     this.logoutLetter = '已登出'
                     this.$router.push("/");
                }
            })
        }
    }
}
</script>

<style scoped>
 div span {
     margin-right: 15px;
 }
</style>